package com.example.demo_news.controller;


import com.example.demo_news.entity.MyUser;
import com.example.demo_news.service.User.UserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class ExternalController {
    @Autowired
    private UserService userService;
  
    //user用户才能访问
    //@PreAuthorize("hasAnyRole('user')")
    @RequestMapping("/about")
    public String about(){
        return "/user/about";
    }

    //跳转到
    @RequestMapping("/contact")
    public String contact(){
        return "/user/index";
    }
  
    @RequestMapping("/myMessage")
    public String  myMessage(){
        return "/user/myMessage";
    }

    //登录页,由springsecurity负责登录验证
    @RequestMapping("/login")
    public String login(){
        return "/login";
    }

    //默认跳转到首页
    @RequestMapping("/")
    public String index(){
        return "/user/index";
    }

    //注册
    @RequestMapping("/register")
    public String register(){
        return "/register";
    }
    //注册,添加用户
    @RequestMapping("/toRegister")
    public String toRegister(MyUser myUser){
        if(userService.save(myUser))
        {      
            return "/login";          
        }
        return "/register";
    }
    //邮箱登录
    @RequestMapping("/emailLogin")
    public String emailLogin(){
        return "/emailLogin";
    }

    //没有权限访问
    @RequestMapping("/unauth")
    public String unAuth(){
        return "/unauth";
    }
}
